﻿using System;
using System.Windows.Input;

using EMan.BL.Commands;
using EMan.Common.DependencyInjection;
using EMan.Common.WorkTasks;
using EMan.Interface;
using EMan.Interface.Common;
using EMan.Interface.WorkTasks;

using TrueCode.Core.Aspects;
using TrueCode.Core.Diagnostics;

namespace EMan.BL
{
  public class MainPresenter : Presenter< IMainView >, IMainPresenter
  {
    private readonly IFactory _factory;
    private readonly SimpleCommand _newTaskCommand;
    private IWorkTaskEditorPresenter _workTaskEditor;

    public MainPresenter( [NotNull] IFactory factory, [NotNull] IDiagnostic diagnostic ) : base( diagnostic )
    {
      _factory = factory;
      if( factory == null ) throw new ArgumentNullException( "factory" );
      _newTaskCommand = new SimpleCommand( AddNewTask );

      AddNewTask();
    }

    public override void Dispose(){}

    public ICommand NewTaskCommand
    {
      get { return _newTaskCommand; }
    }

    public IWorkTaskEditorPresenter WorkTaskEditor
    {
      get { return _workTaskEditor; }
      private set
      {
        _workTaskEditor = value;
        RaisePropertyChanged( () => WorkTaskEditor );
      }
    }

    private void AddNewTask()
    {
      var workTask = new WorkTask( "Short summary", null, null, DateTime.Now );
      var editable = new WorkTaskEditable( workTask, true );
      WorkTaskEditor = _factory.Resolve< IWorkTaskEditorPresenter >( editable );
    }
  }
}